<template>
  <div class="comment">
    <!-- 商家评分 -->
    <div class="rating" v-if="evalution">
      <div class="rating-number">
        <div class="rating-typing">
          <h3>{{evalution.rating.shop_score.toFixed(1)}}</h3>
          <p>
            <span>商家评分</span>
            <Roating :roating="evalution.rating.shop_score" class="roating" />
          </p>
          <ul>
            <li>
              <span>味道</span>
              <em>{{evalution.rating.shop_score.toFixed(1)}}</em>
            </li>
            <li>
              <span>包装</span>
              <em>{{evalution.rating.shop_score.toFixed(1)}}</em>
            </li>
          </ul>
        </div>
        <div class="rating-send">
          <p>
            <span>配送</span>
            <em>{{evalution.rating.rider_score.toFixed(1)}}</em>
          </p>
        </div>
      </div>
      <!-- 评论区 -->
      <div class="comment-info">
        <!-- 标签 -->
        <div class="comment-tags">
          <ul>
            <li v-for="(item,index) in evalution.tags" :key="index" :class="{negative: item.name==='差评'}">{{item.name}}<span v-if="item.count> 0">{{item.count}}</span></li>
          </ul>
        </div>
        <div class="comment-main">
          <ul>
            <li v-for="(item,index) in evalution.comments" :key="index" class="comment_list">
              <div class="comment-users">
                <img :src="item.avatar|| 'https://shadow.elemecdn.com/faas/h5/static/sprite.3ffb5d8.png'" alt="">
              </div>
              <div class="comment-detail">
                <div class="user-header">
                  <span>{{item.username}}</span>
                  <small>{{item.rated_at}}</small>
                </div>
                <div class="user-rating">
                  <roating :roating="item.rating" />
                  <span :style="{color: starText(item.rating).color}">{{starText(item.rating).text}}</span>
                </div>
                <div class="user-text">{{item.comment_text}}</div>
                <div class="shop-text">{{item.reply.content}}</div>
                <div class="user-img">
                  <ul>
                    <li v-for="(i,indey) in item.order_images" :key="indey">
                      <img :src="i.image_hash" alt="">
                    </li>
                  </ul>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Roating from '@/components/Roating'

export default {
  name: 'MyComment',
  created() {
    this.getCommendData()
  },
  data() {
    return {
      // 评价
      evalution: null
    }
  },
  methods: {
    getCommendData() {
      this.$http('/api/profile/comments').then(res => {
        console.log(res.data)
        this.evalution = res.data
      })
    },
    // 星级旁边的文本
    starText(rating) {
      const content = [
        {
          text: '吐槽', color: 'rgb(137,159,188)'
        },
        {
          text: '较差', color: 'rgb(137,159,188)'
        },
        {
          text: '一般', color: 'rgb(251,154,11)'
        },
        {
          text: '满意', color: 'rgb(251,154,11)'
        },
        {
          text: '超赞', color: 'rgb(255,96,0)'
        }
      ]
      return content[rating - 1]
    }
  },
  components: {
    Roating
  }

}
</script>

<style lang="less" scoped>
.comment {
  background-color: #f1f1f1;
  .rating {
    .rating-number {
      display: flex;
      justify-content: space-around;
      background-color: #fff;
      align-items: center;
      .rating-typing {
        display: flex;
        align-items: center;
        h3 {
          padding: 0 20px;
          font-size: 30px;
          color: orange;
        }
        p {
          display: flex;
          flex-direction: column;
          text-align: center;
          // margin-left: 20px;
          .roating {
            font-size: 12px;
          }
        }
        ul {
          display: flex;
          li {
            position: relative;
            display: flex;
            flex-direction: column;
            margin: 0 15px;
            align-items: center;
            em {
              display: inline-block;
              margin-top: 5px;
              font-style: inherit;
            }
            &:last-child::before {
              content: '';
              display: inline-block;
              position: absolute;
              top: 0;
              right: -20px;
              width: 1px;
              height: 40px;
              background-color: #666;
            }
          }
        }
      }
      .rating-send {
        p {
          display: flex;
          flex-direction: column;
          align-items: center;
          em {
            display: inline-block;
            margin-top: 5px;
            font-style: inherit;
          }
        }
      }
    }
    .comment-info {
      border-bottom: 1px solid #ccc;
      .comment-tags {
        background-color: #fff;
        margin-top: 10px;
        padding: 10px 5px;
        border-bottom: 1px solid #ccc;
        ul {
          display: flex;
          flex-wrap: wrap;
          li {
            background-color: skyblue;
            margin: 5px 10px;
            padding: 5px;
            font-size: 12px;
            &.negative {
              color: #aaa;
              background-color: #f1f1f1;
            }
          }
        }
      }
      .comment-main {
        background-color: #fff;
        ul {
          .comment_list {
            display: flex;
            padding: 0 8px;
            padding-top: 10px;
            border-bottom: 1px solid #ccc;
            .comment-users {
              width: 30px;
              height: 30px;
              img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
              }
            }
            .comment-detail {
              flex: 1;
              padding: 0 10px;
              .user-header {
                display: flex;
                justify-content: space-between;
                align-items: center;
                small {
                  color: #666;
                }
              }
              .user-rating {
                display: flex;
                margin: 8px 0;
                span {
                  margin-left: 8px;
                  font-size: 14px;
                }
              }
              .shop-text {
                padding: 10px 5px;
                background-color: #eee;
                font-size: 12px;
                color: #333;
                font-weight: 500;
              }
              .user-img {
                padding: 8px 0;
                img {
                  width: 140px;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
